Skip to content

[SPARK-57847][SQL] Support the TIME data type in approx_count_distinct_for_intervals#56934

Closed
yadavay-amzn wants to merge 2 commits into
apache:masterfrom
yadavay-amzn:SPARK-57847
Closed

[SPARK-57847][SQL] Support the TIME data type in approx_count_distinct_for_intervals#56934
yadavay-amzn wants to merge 2 commits into
apache:masterfrom
yadavay-amzn:SPARK-57847

Conversation

@yadavay-amzn

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Adds TimeType to the input types accepted by the approx_count_distinct_for_intervals aggregate. TIME values are bucketed by their internal nanosecond-of-day Long representation, routed through the same Long -> Double path already used for TimestampType / DayTimeIntervalType.

Why are the changes needed?

approx_count_distinct_for_intervals accepts numeric/date/timestamp/interval endpoints but rejected TIME at analysis time. TIME has a natural numeric (nanosecond-of-day) ordering, so it can be bucketed like the other temporal types.

Does this PR introduce any user-facing change?

Yes - approx_count_distinct_for_intervals now accepts TIME columns and endpoints.

How was this patch tested?

Extended ApproxCountDistinctForIntervalsSuite with TIME endpoints asserting the per-interval approximate distinct counts; the error-message expectations were updated to include TIME.

Was this patch authored or co-authored using generative AI tooling?

Authored with assistance by Claude Opus 4.8.

@MaxGekk MaxGekk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 blocking, 0 non-blocking, 0 nits.
Clean, correct extension of approx_count_distinct_for_intervals to TIME. TIME is PhysicalLongType (nanos-of-day), so it routes through the same Long -> Double bucketing path as timestamp/interval; the three accept/convert sites are updated in lockstep (the toDoubleValue match has no catch-all, so a missed site would have thrown a MatchError), the hash path handles TimeType, and tests cover both small and full-range nanos plus the updated error messages. Follows the SPARK-57557 precedent.

Verification

Traced all three type paths for TIME: analysis accept (inputTypes + endpoint-array check), runtime child conversion (asInstanceOf[Long].toDouble) and endpoint conversion (getAccessor -> getLong -> .toString.toDouble), and the downstream XxHash64 (case LongType | _: TimeType => genHashLong). All operate on the same nanos-of-day Long domain, so TIME values and endpoints bucket consistently — identical to the existing timestamp/interval types.

@MaxGekk MaxGekk closed this in 1a89a69 Jul 2, 2026
MaxGekk pushed a commit that referenced this pull request Jul 2, 2026
…t_for_intervals

### What changes were proposed in this pull request?

Adds `TimeType` to the input types accepted by the `approx_count_distinct_for_intervals` aggregate. TIME values are bucketed by their internal nanosecond-of-day `Long` representation, routed through the same `Long -> Double` path already used for `TimestampType` / `DayTimeIntervalType`.

### Why are the changes needed?

`approx_count_distinct_for_intervals` accepts numeric/date/timestamp/interval endpoints but rejected TIME at analysis time. TIME has a natural numeric (nanosecond-of-day) ordering, so it can be bucketed like the other temporal types.

### Does this PR introduce _any_ user-facing change?

Yes - `approx_count_distinct_for_intervals` now accepts TIME columns and endpoints.

### How was this patch tested?

Extended `ApproxCountDistinctForIntervalsSuite` with TIME endpoints asserting the per-interval approximate distinct counts; the error-message expectations were updated to include TIME.

### Was this patch authored or co-authored using generative AI tooling?

Authored with assistance by Claude Opus 4.8.

Closes #56934 from yadavay-amzn/SPARK-57847.

Authored-by: Anupam Yadav <anupamy030@gmail.com>
Signed-off-by: Max Gekk <max.gekk@gmail.com>
(cherry picked from commit 1a89a69)
Signed-off-by: Max Gekk <max.gekk@gmail.com>
@MaxGekk

MaxGekk commented Jul 2, 2026

Copy link
Copy Markdown
Member

Merge summary (posted by merge_spark_pr.py):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants